/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.fritadorcorrente.objetos.dao;

import br.com.fritadorcorrente.objetos.Email;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

/**
 *
 * @author manchini
 */
@Repository
@Transactional
public class EmailDAO {

    @PersistenceContext
    protected EntityManager em;

    public boolean getEmailSiteJaUsado(Email email, String dominio) throws DataAccessException {
        Query query = em.createNativeQuery("SELECT * FROM EMAIL_COMENTARIO C INNER JOIN COMENTARIO O ON C.COMENTARIO_ID = O.ID "
                + "WHERE EMAIL_EMAIL = :EMAIL_EMAIL "
                + "AND DOMINIO =:DOMINIO ");
        query.setParameter("EMAIL_EMAIL", email.getEmail());
        query.setParameter("DOMINIO", dominio);

        return query.getResultList().size() > 0;
    }
}
